package com.study.d1_servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(value = "/response")
public class ResponseServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1、设置响应状态码-模拟404（不推荐）
        resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
        //2、设置响应头
        resp.setHeader("itheima","javastudy");
        //设置响应编码和响应数据类型
        resp.setHeader("content-type","text/html;charset=utf-8");
        //3、设置响应数据
        String name = req.getParameter("name");
        resp.getWriter().write("<h1>hello "+name+"</h1>");
    }
}
